package misp_backend.controller;

import misp_backend.config.AjaxResult;
import misp_backend.domain.Dishes;
import misp_backend.domain.Table;
import misp_backend.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/table")
public class TableController {

    @Autowired
    private TableService tableService;

    @GetMapping("/listtable")
    public AjaxResult listAllDishes() {
        return AjaxResult.success(tableService.list());
    }

    @PostMapping("/addtable")
    public AjaxResult addNewDish(@RequestBody Table table) {
        Date time = new Date();
        table.setCreateTime(time);
        return AjaxResult.success(tableService.save(table));
    }

    @PostMapping("/updatetable")
    public AjaxResult updateDish(@RequestBody Table table) {
        Date time = new Date();
        table.setCreateTime(time);
        return AjaxResult.success(tableService.updateById(table));
    }

    @DeleteMapping("/removetable")
    public AjaxResult removeDish(@RequestParam Long tableid) {
        return AjaxResult.success(tableService.removeById(tableid));

    }
}
